package com.ly.lypopupwindowdemo.views;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.Path;
import android.support.annotation.Nullable;
import android.util.AttributeSet;
import android.view.View;

import com.ly.lypopupwindowdemo.R;

/**
 * Created by liying on 2018/1/29.
 */

public class CircleView extends View{
    int circle_color;
    Paint mPaint;
    public CircleView(Context context) {
        super(context);
        init();
    }

    public CircleView(Context context,  AttributeSet attrs) {
        this(context, attrs,0);
        init();
    }

    public CircleView(Context context,  AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);

        TypedArray  a = context.obtainStyledAttributes(attrs,R.styleable.CircleView);
        circle_color = a.getColor(R.styleable.CircleView_circle_color, Color.RED);
        a.recycle();

        init();
    }

    private void init() {
        mPaint = new Paint();
        mPaint.setColor(circle_color);
        mPaint.setStrokeWidth(10f);
        mPaint.setStyle(Paint.Style.FILL);

    }

    @Override
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        int paddingLeft = getPaddingLeft();
        int paddingRight = getPaddingRight();
        int paddingTop = getPaddingTop();
        int paddingBottom = getPaddingBottom();

        int width = getWidth()-paddingLeft-paddingRight;
        int height = getHeight()-paddingTop-paddingBottom;

        int r = Math.min(width,height)/2;

        canvas.drawCircle(width/2+paddingLeft,height/2+paddingTop,r,mPaint);
    }
}
